package edu.towson.cosc603.coffeemaker;

import static org.junit.Assert.*;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class CoffeeMakerTest extends TestCase{
	CoffeeMaker CM;
	Inventory i;
	Recipe r1;
	Recipe r2;
	Recipe r3;
	Recipe r4;
	Recipe r5;
	Recipe[] recepies;

	//private Object assertArray;
	
	@Before
	public void setUp() throws Exception {
		CM = new CoffeeMaker();
		
		r1 = new Recipe();
		r1.setName("R1");
		r1.setPrice(1);
		r1.setAmtCoffee(1);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(1);
		
		r2 = new Recipe();
		r2.setName("R2");
		r2.setPrice(2);
		r2.setAmtCoffee(2);
		r2.setAmtMilk(2);
		r2.setAmtSugar(2);
		r2.setAmtChocolate(2);
		
		r3 = new Recipe();
		r3.setName("R3");
		r3.setPrice(3);
		r3.setAmtCoffee(3);
		r3.setAmtMilk(3);
		r3.setAmtSugar(3);
		r3.setAmtChocolate(3);
		
		r4 = new Recipe();
		r4.setName("R4");
		r4.setPrice(-4);
		r4.setAmtCoffee(-4);
		r4.setAmtMilk(-4);
		r4.setAmtSugar(-4);
		r4.setAmtChocolate(-4);
		
		r5 = new Recipe();
		//r5.setName("");
		r5.setPrice(5);
		r5.setAmtCoffee(5);
		r5.setAmtMilk(5);
		r5.setAmtSugar(5);
		r5.setAmtChocolate(5);
		
	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testAddReceipie() {
		
		assertTrue(CM.addRecipe(r1));
		assertFalse(CM.addRecipe(r1));
		assertTrue(CM.addRecipe(r2));
		assertTrue(CM.addRecipe(r3));
		assertTrue(CM.addRecipe(r4));
		assertFalse(CM.addRecipe(r5));
		assertEquals("R1", r1.toString());
		assertEquals(1, r1.getPrice());
		
		assertFalse (r5.equals(r2));
		assertEquals (r2, CM.getRecipeForName("R2"));
	}

	@Test
	public void testdeleteRecipe(){
		assertFalse(CM.deleteRecipe(r1));
		CM.addRecipe(r1);
		assertTrue(CM.deleteRecipe(r1));
		CM.addRecipe(r2);
		assertTrue(CM.deleteRecipe(r2));
		CM.addRecipe(r3);
		assertTrue(CM.deleteRecipe(r3));
		CM.addRecipe(r4);
		assertTrue(CM.deleteRecipe(r4));
		
	}
	
	@Test
	public void testEditRecipe(){
		CM.addRecipe(r1);
        Recipe newRecipe = new Recipe();
        newRecipe = r1;
        assertTrue(CM.editRecipe(r1, newRecipe));
              
        CM.addRecipe(r1);
        CM.addRecipe(r2);
        CM.addRecipe(r3);
        CM.addRecipe(r4);
        Recipe newRecipe1 = new Recipe();
        newRecipe1 = r1;
        assertFalse(CM.editRecipe(r1, newRecipe1));
	}
        
	@Test
	public void testGetRecipes(){
		recepies = new Recipe[4];
		recepies[0] = r4;
		recepies[1] = r3;
		recepies[2] = r2;
		recepies[3] = r1;
		
		CM.addRecipe(r1);
		CM.addRecipe(r2);
		CM.addRecipe(r3);
		CM.addRecipe(r4);
		
        assertArrayEquals(recepies, CM.getRecipes());
        	
        }
	
	@Test
	public void testAddInventory(){
		assertFalse (CM.addInventory(-1, -1, 1, -1));
		assertTrue(CM.addInventory(1, 1, 0, 1));
		assertTrue(CM.addInventory(0, 0, 1, 0));	
		
		
	}
	
	@Test
	public void testMakeCoffee(){
		assertEquals(0, CM.makeCoffee(r1, 0));
		assertEquals(1, CM.makeCoffee(r1, 2), 0.01);
		
	}

}

